import {ColumnsType} from "antd/es/table";
import {Space} from "antd";
import {Link} from "react-router-dom";
import {Part} from "type/Part";
import Highlight from "../component/drp/Highlight";
import {MATHEMATICAL_PRECISION} from "../constant/Common";
import {ellipsisHandler} from "../util/ColumnsUtil";

const partColumns: ColumnsType<Part> = [
    {
        title: '序号' ,
        dataIndex: 'index',
        width: 70,
        align: "center" ,
        render: (_, __, index) => <strong>{index + 1}</strong>
    },
    {
        title: '零件名称',
        dataIndex: 'partName',
        key: 'partName',
        width: 190,
        fixed: 'left',
        align: "center" ,
        render: (value) => {
            let keyword = Highlight.getInstance().getKeyword() ;
            if (keyword !== ""){
                let reg = new RegExp(keyword,"g");
                return <span dangerouslySetInnerHTML={{__html: value.replace(reg,`<span style="color: red;font-weight: bold">${keyword}</span>`)}}></span> ;
            }
            return value ;
        }
    },
    {
        title: '零件图号',
        dataIndex: 'figureNumber',
        key: 'figureNumber',
        width: 180,
    },
    {
        title: '零件描述',
        dataIndex: 'partDesc',
        key: 'partDesc',
        width: 110,
        ellipsis: {showTitle: false},
        render: ellipsisHandler,
    },
    {
        title: '供应商',
        dataIndex: 'partProvider',
        key: 'partProvider',
        width: 120,
        ellipsis: {showTitle: false},
        render: ellipsisHandler,
    },
    {
        title: '零件分组',
        dataIndex: 'partGroup',
        key: 'partGroup',
        width: 110,
        align: "center" ,
    },
    {
        title: '数量',
        dataIndex: 'repertorySize',
        key: 'repertorySize',
        width: 80,
        align: "center" ,
    },
    {
        title: '进货价格',
        dataIndex: 'costPrice',
        key: 'costPrice',
        width: 110,
        align: "center" ,
        render: (value) => value / MATHEMATICAL_PRECISION
    },
    {
        title: '销售价格',
        dataIndex: 'salePrice',
        key: 'salePrice',
        width: 110,
        align: "center" ,
        render: (value) => value / MATHEMATICAL_PRECISION
    },
    {
        title: '操作',
        dataIndex: 'option' ,
        width: 180,
        align: "center",
        fixed: 'right',
        render: (_, record) => {
            return <Space>
                <Link key={"part-update"} to={"./update/" + record.id}>更新</Link>
                <Link key={"part-details"} to={"./details/" + record.id}>详情</Link>
                <Link key={"part-outbound-delivery-order"} to={"./odo"} state={record}>出库</Link>
            </Space> ;
        }
    }
] ;
export default partColumns;
